import 'package:casdon/modules/recipe/data/model/recipe_module_content_model.dart';
import 'package:casdon/modules/recipe/domain/states/recipe_module_content_state.dart';
import 'package:casdon/modules/recipe/ui/widgets/recipe_card_style2.dart';
import 'package:casdon/auto_router.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

/// 通用的仅展示图片的水平列表组件
class RecipeModuleStyle2Content extends StatelessWidget {
  final int maxCount;
  final RecipeModuleContentState state;

  const RecipeModuleStyle2Content({
    super.key,
    required this.maxCount,
    required this.state,
  });

  @override
  Widget build(BuildContext context) {
    if (state.data.isEmpty) {
      return const SizedBox.shrink();
    }

    return SizedBox(
      height: 200.h,
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        padding: EdgeInsets.symmetric(horizontal: 12.w),
        itemCount: state.data.length > maxCount ? maxCount : state.data.length,
        itemBuilder: (context, index) {
          final item = state.data[index];
          return GestureDetector(
            onTap: () => {_handleItemClick(item, context)},
            child: RecipeCardStyle2(item: item, imageHeight: 200.h),
          );
        },
      ),
    );
  }

  _handleItemClick(RecipeModuleContentModel item, BuildContext context) {
    RecipeListRoute(recipeCollectId: item.id, title: item.title).push(context);
  }
}
